// source --> http://www.softwater.com.pl/wp-content/themes/softwater/cookienoticepro/cookienoticepro.js /* * Copyright (c) 2024 Flerosoft (https://flerosoft.com) * Software Name: Cookie Notice Pro - jQuery Plugin * Product Page : https://cookienoticepro.flerosoft.com * Documentation: https://cookienoticepro.flerosoft.com/docs * Description: Cookie Notice Pro, a lightweight jQuery plugin, helps you to comply with GDPR. Make your own cookie information popup in minutes. * Changelog: https://cookienoticepro.flerosoft.com/docs/getting-started#item-1-4 */ (function ($) { 'use strict' const settingsIcon = ''; const cookieIcon = ' '; const closeIcon = ''; /* *-------------------------------------------------------------------------- * CONFIG OR SETTINGS - Customize the popup banner START *-------------------------------------------------------------------------- */ const config = { themeSettings: { primaryColor: "#1595d3", // Primary Color of Popup Banner darkColor: "#3b3e4a", // Dark Theme Color lightColor: "#ffffff", // Light Theme Color themeMode: "light", // Theme Mode (light|dark) }, enableGoogleConsentMode: true, // Add support for Google consent mode v2 (https://cookiebannergenerator.com/implementing-google-consent-mode-v2-with-cookie-notice-pro-a-step-by-step-guide/) enableMinimize: true, // Enable minimized floating cookie icon to adjust preferences showCookieIcon: true, // Hide or show the cookie icon showSettingsBtn: true, // Hide or show the preference settings(true|false) showCloseIcon: false, // Hide or show the popup close icon(true|false) showDeclineBtn: true, // Hide or show the cookie decline button(true|false) fullWidth: false, // Full width popup works only when "displayPosition" is set to top/bottom allCheckboxesChecked: true, // The setting checkboxes should be checked by default initially or not(true|false) displayPosition: "left", // Where popup should appear(top|right|bottom|left) settingsBtnLabel: "Dostosuj", // Text of settings button delay: 0, // After how much time should popup appear(2000 is equal to 2 seconds) expires: 365, // Expiry date of cookie(365 is equal to 365 days) title: "Zgoda na ciasteczka", // Title of popup bannner description: "Używamy ciasteczek, aby zapewnić najlepszą jakość korzystania z naszej witryny. Sprawdź naszą ", // Message acceptBtnLabel: "Akceptuj", // Accept cookie button text declineInfoBtnLabel: "Zamknij", // Decline cookie button text moreInfoBtnLink: "/polityka-prywatnosci/", // Learn more link(default: privacy policy page) moreInfoBtnLabel: "Politykę prywatności", // More info link text cookieTypesTitle: "Wybierz ciasteczka, na które wyrażasz zgodę", // Title of cookie preference options necessaryCookieTypeLabel: "Niezbędne", // Label text of Necessary cookie item floatingIconTooltip: "Zmień ustawienia ciasteczek", // Tooltip of floating cookie icon (Minimized) necessaryCookieTypeDesc: "Te ciasteczka są niezbędne do funkcjonowania naszej witryny i nie mogą zostać wyłączone.", // Hover text of necessary cookies onConsentAccept: ()=> { // It will inject scripts in head if cookie preferences menu(showSettingsBtn) is enabled console.log("Wyrażono zgodę!") }, onConsentReject: ()=> { // This code will run on cookie reject/decline console.log("Nie wyrażono zgody!"); }, cookieTypes: [ // Cookie types, value and description (Cookie Preferences Selection) /*{ type: "Marketing", value: "marketing", // WARNING: DO NOT EDIT THIS VALUE description: "Te ciasteczka służą do gromadzenia informacji o użytkownikach, by wyświetlać lepiej dostosowane do nich treści reklamowe.", },*/ { type: "Analityka", value: "analytics", // WARNING: DO NOT EDIT THIS VALUE description: "Te ciasteczka służą do gromadzenia anonimowych informacji, takich jak liczba odwiedzających i najpopularniejsze podstrony witryny. Włączenie ich pomoże nam ulepszyć naszą stronę internetową.", }, ], }; /* *-------------------------------------------------------------------------- * CONFIG OR SETTINGS - Customize the popup banner END *-------------------------------------------------------------------------- */ const COOKIE_CONSENT = 'cnp_consent' // WARNING: DO NOT EDIT THIS VALUE const COOKIE_CONSENT_PREFS = 'cnp_prefs' // WARNING: DO NOT EDIT THIS VALUE const GOOGLE_CONSENT_MODE_AD_PREFS = 'cnp_gconsent_ad_prefs' // WARNING: DO NOT EDIT THIS VALUE const GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE = 'cnp_gconsent_analytics_storage' // WARNING: DO NOT EDIT THIS VALUE $.fn.cookieNoticePro = (event) => { typeof event === 'object' ? $.extend(true, config, event) : null changeRootVariables() let cookieConsentExists = cookieExists(COOKIE_CONSENT) let cookiePrefsValue = accessCookie(COOKIE_CONSENT_PREFS) // If consent is not accepted if (!cookieConsentExists || event == 'open') { $('#cookieNoticePro').remove() $('#cookieMinimizeIcon').remove() let cookieTypes = '
  • ' const preferences = JSON.parse(cookiePrefsValue) $.each(config.cookieTypes, (index, field) => { if (field.type !== '' && field.value !== '') { let cookieTypeDescription = '' if (field.description !== false) { cookieTypeDescription = ' title="' + field.description + '"' } cookieTypes += '
  • ' } }) let cookieNotice = '
    ' + closeIcon + '
    ' + cookieIcon + '

    ' + config.title + '

    ' + config.description + ' ' + config.moreInfoBtnLabel + '

    ' setTimeout( () => { $('body').append(cookieNotice) $('#cookieNoticePro') .hide() .fadeIn('slow', () => { if (event == 'open') { $('#cookieSettings').trigger('click') $.each(preferences, (index, field) => { $('input#gdprPrefItem' + field).prop('checked', true) }) } }) if (!config.showSettingsBtn) { $('#cookieNoticePro #cookieSettings').hide() } if (!config.showDeclineBtn) { $('#cookieNoticePro #cookieReject').hide() } if (!config.showCookieIcon) { $('#cookieNoticePro #cookieIcon').hide() } if (!config.showCloseIcon) { $('#cookieNoticePro #closeIcon').hide() } }, event === 'open' ? 0 : config.delay, ) $('body').on('click', '#cookieAccept', () => { hideCookieBanner(true, config.expires) $('input[name="gdprPrefItem"][data-compulsory="on"]').prop('checked', true) let prefs = [] $.each($('input[name="gdprPrefItem"]').serializeArray(), (i, field) => { prefs.push(field.value) }) createCookie(COOKIE_CONSENT_PREFS, encodeURIComponent(JSON.stringify(prefs)), { expires: daysToUTC(365), path: '/', }) config.onConsentAccept.call(this) config.showSettingsBtn ? typeof injectScripts === 'function' && injectScripts() : null if (config.enableGoogleConsentMode) { googleConsentModeHandler() } }) $('body').on('click', '#cookieSettings', () => { if (event === 'open') { $('input[name="gdprPrefItem"]:not(:disabled)').attr('data-compulsory', 'off').prop('checked', false) $('#cookieTypes').slideDown('fast', function () { $('#cookieSettings').prop('disabled', true) }) } else { $('input[name="gdprPrefItem"]:not(:disabled)').attr('data-compulsory', 'off').prop('checked', config.allCheckboxesChecked) $('#cookieTypes').toggle('fast', function () { $('#cookieSettings').prop('disabled', false) }) } }) $('body').on('click', '#closeIcon', () => { $('#cookieNoticePro').remove() }) $('body').on('click', '#cookieReject', () => { hideCookieBanner(false, config.expires) config.onConsentReject.call(this) if (config.enableGoogleConsentMode) { googleConsentModeHandler() } // Delete prefs cookie from brower on reject createCookie(COOKIE_CONSENT_PREFS, '', { expires: daysToUTC(-365), path: '/', }) }) } // If already consent is accepted, inject preferences else { config.showSettingsBtn ? typeof injectScripts === 'function' && injectScripts() : null if (config.enableMinimize) { minimizeCookieBanner() } if (config.enableGoogleConsentMode) { googleConsentModeHandler() } } } /** * Check if cookie exists * @param {string} cookieName */ const cookieExists = (cookieName) => { if (document.cookie.indexOf(cookieName) > -1) { return true } return false } /** * Create the cookie and hide the banner * @param {string} value * @param {string} expiryDays */ const hideCookieBanner = (value, expiryDays) => { createCookie(COOKIE_CONSENT, value, { expires: daysToUTC(expiryDays), path: '/', }) $('#cookieNoticePro').fadeOut('fast', () => { $('body').off('click', '#cookieSettings') $('body').off('click', '#cookieReject') $('body').off('click', '#closeIcon') $('body').off('click', '#cookieAccept') $(this).remove() }) if (config.enableMinimize) { minimizeCookieBanner() } } /** * Minimize the cookie banner and show a minimized icon. */ const minimizeCookieBanner = () => { // Remove any existing minimize icon before appending a new one. $('#cookieMinimizeIcon').remove() // Minimize the banner and show an icon instead. let minimizeIcon = $( '
    ' + cookieIcon + '
    ' + config.floatingIconTooltip + '
    ', ) $('body').append(minimizeIcon) // Define the click behavior for the minimize icon. $('#cookieMinimizeIcon').on('click', function () { if ($(this).hasClass('zoomIn')) { $(this).removeClass('zoomIn').addClass('zoomOut') setTimeout(() => { $.fn.cookieNoticePro('open') // Reopen the cookie notice }, 200) // Match the timeout to the animation duration } else { $(this).removeClass('zoomOut').addClass('zoomIn') } }) } /** * Set Cookie * @param {string} name - Cookie Name * @param {string} value - Cookie Value * @param {string} expiryDays - Expiry Date of cookie */ const createCookie = (name, value, options = {}) => { document.cookie = `${name}=${value}${Object.keys(options).reduce((acc, key) => { return acc + `;${key.replace(/([A-Z])/g, ($1) => '-' + $1.toLowerCase())}=${options[key]}` }, '')}` } /** * Converts Days Into UTC String * @param {number} days - Name of the cookie * @return {string} UTC date string */ const daysToUTC = (days) => { const newDate = new Date() newDate.setTime(newDate.getTime() + days * 24 * 60 * 60 * 1000) return newDate.toUTCString() } /** * Get Cookie By Name * @param {string} name - Name of the cookie * @return {string(number|Array)} Value of the cookie */ const accessCookie = (name) => { const cookies = document.cookie.split(';').reduce((acc, cookieString) => { const [key, value] = cookieString.split('=').map((s) => s.trim()) if (key && value) { acc[key] = decodeURIComponent(value) } return acc }, {}) return name ? cookies[name] || false : cookies } /** * Updates Google Consent Mode based on user consent and preferences. */ const googleConsentModeHandler = () => { if (!config.enableGoogleConsentMode) return const consent = JSON.parse(accessCookie(COOKIE_CONSENT)) const preferences = JSON.parse(accessCookie(COOKIE_CONSENT_PREFS)) const googleConsentAnalyticsStorage = JSON.parse(accessCookie(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE)) const googleConsentAdPrefs = JSON.parse(accessCookie(GOOGLE_CONSENT_MODE_AD_PREFS)) try { // if consent is accepted if (consent === true) { /** GOOGLE CONSENT ANALYTICS STORAGE */ // if analytics is accepted and google consent analytics storage does not exist if (preferences.indexOf('analytics') > -1 && !cookieExists(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE)) { createCookie(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE, encodeURIComponent(true), { expires: daysToUTC(365), path: '/', }) gtag('consent', 'update', { analytics_storage: 'granted', }) } // if analytics is accepted and google consent analytics storage exist else if (preferences.indexOf('analytics') > -1 && cookieExists(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE)) { if (googleConsentAnalyticsStorage === true) { gtag('consent', 'update', { analytics_storage: 'granted', }) } if (googleConsentAnalyticsStorage === false) { createCookie(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE, encodeURIComponent(true), { expires: daysToUTC(365), path: '/', }) gtag('consent', 'update', { analytics_storage: 'granted', }) } } // if analytics is removed and google consent analytics storage exist else if (preferences.indexOf('analytics') === -1 && cookieExists(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE)) { if (googleConsentAnalyticsStorage === true) { createCookie(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE, encodeURIComponent(false), { expires: daysToUTC(365), path: '/', }) gtag('consent', 'update', { analytics_storage: 'denied', }) } } /** GOOGLE CONSENT AD PREFS */ // if marketing is accepted and google consent ad prefs storage does not exist if (preferences.indexOf('marketing') > -1 && !cookieExists(GOOGLE_CONSENT_MODE_AD_PREFS)) { createCookie(GOOGLE_CONSENT_MODE_AD_PREFS, encodeURIComponent(true), { expires: daysToUTC(365), path: '/', }) gtag('consent', 'update', { ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted', }) } // if marketing is accepted and google consent ad prefs storage exist else if (preferences.indexOf('marketing') > -1 && cookieExists(GOOGLE_CONSENT_MODE_AD_PREFS)) { if (googleConsentAdPrefs === true) { gtag('consent', 'update', { ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted', }) } if (googleConsentAdPrefs === false) { createCookie(GOOGLE_CONSENT_MODE_AD_PREFS, encodeURIComponent(true), { expires: daysToUTC(365), path: '/', }) gtag('consent', 'update', { ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted', }) } } // if marketing is removed and google consent ad prefs storage exist else if (preferences.indexOf('marketing') === -1 && cookieExists(GOOGLE_CONSENT_MODE_AD_PREFS)) { if (googleConsentAdPrefs === true) { createCookie(GOOGLE_CONSENT_MODE_AD_PREFS, encodeURIComponent(false), { expires: daysToUTC(365), path: '/', }) gtag('consent', 'update', { ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', }) } } } else { if (cookieExists(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE)) { if (googleConsentAnalyticsStorage === true) { createCookie(GOOGLE_CONSENT_MODE_ANALYTICS_STORAGE, '', { expires: daysToUTC(-365), path: '/', }) gtag('consent', 'update', { analytics_storage: 'denied', }) } } if (cookieExists(GOOGLE_CONSENT_MODE_AD_PREFS)) { if (googleConsentAdPrefs === true) { createCookie(GOOGLE_CONSENT_MODE_AD_PREFS, '', { expires: daysToUTC(-365), path: '/', }) gtag('consent', 'update', { ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', }) } } } } catch (error) { console.warn('CookieNoticePro: Error initializing Google Consent Mode. Ensure gtag.js is correctly installed:', error) } } const changeRootVariables = () => { $(':root').css('--cookieNoticeProLight', config.themeSettings.lightColor) $(':root').css('--cookieNoticeProDark', config.themeSettings.darkColor) } return (window.cookieNoticePro = { init: (config) => { $.fn.cookieNoticePro(config) }, /** * Reopens the cookie notice banner */ reinit: () => { $.fn.cookieNoticePro('open') }, /** * Returns true if consent is given else false */ isAccepted: () => { let consent = accessCookie(COOKIE_CONSENT) return JSON.parse(consent) }, /** * Returns the value of the cookieConsentPrefs cookie */ getPreferences: () => { let preferences = accessCookie(COOKIE_CONSENT_PREFS) return JSON.parse(preferences) }, /** * Check if a particular preference is accepted * @param {string} cookieName */ isPreferenceAccepted: (cookieTypeValue) => { let consent = JSON.parse(accessCookie(COOKIE_CONSENT)) let preferences = accessCookie(COOKIE_CONSENT_PREFS) preferences = JSON.parse(preferences) if (consent === false) { return false } if (preferences === false || preferences.indexOf(cookieTypeValue) === -1) { return false } return true }, }) })(jQuery);